package me.algo.array;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.IntStream;

/**
 * @author guozheng
 * @date 2024/4/22
 */
public class A7 {
    /**
     * 260. 只出现一次的数字 III
     * @param nums
     * @return
     */
    public static int[] singleNumber(int[] nums) {
        if (Objects.isNull(nums) || nums.length == 0) {
            return new int[0];
        }
        HashMap<Integer, Integer> hm = new HashMap<>();
        for (int num : nums) {
            Integer val = hm.getOrDefault(num, 0);
            if (val == 1) {
                hm.remove(num);
            } else {
                hm.put(num, val + 1);
            }
        }
        Set<Integer> integers = hm.keySet();
        IntStream stream = integers.stream().mapToInt(Integer::intValue);
        int[] array = stream.toArray();
        return array;
    }
}
